Passed
Pull Request — develop (#65)
by
unknown
04:01 queued 02:39
created

BrewServices   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 72
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 19

10 Functions

Rating   Name   Duplication   Size   Complexity  
A reload 0 7 2
A restart 0 7 2
A stop 0 7 2
A startAsRoot 0 7 2
A unlink 0 7 2
A start 0 4 1
A stopAsRoot 0 7 2
A link 0 7 2
A reloadAsRoot 0 7 2
A restartAsRoot 0 7 2
1
import execa from 'execa'
2
import ServiceCtl from '../serviceCtl'
3
4
class BrewServices extends ServiceCtl {
5
    alias = 'brew'
6
    name = 'Homebrew'
7
    path = '/usr/local/bin/brew'
8
9
    async reload(pkg: string): Promise<boolean> {
10
        try {
11
            await execa('brew', ['services', 'reload', pkg], {shell: true})
12
            return true
13
        } catch (e) {
14
            return false
15
        }
16
    }
17
18
    async restart(pkg: string): Promise<boolean> {
19
        try {
20
            await execa('brew', ['services', 'restart', pkg], {shell: true})
21
            return true
22
        } catch (e) {
23
            return false
24
        }
25
    }
26
27
    async start(pkg: string): Promise<boolean> {
28
        await execa('brew', ['services', 'start', pkg], {shell: true})
29
        return true
30
    }
31
32
    async stop(pkg: string): Promise<boolean> {
33
        try {
34
            await execa('brew', ['services', 'stop', pkg], {shell: true})
35
            return true
36
        } catch (e) {
37
            return false
38
        }
39
    }
40
41
    async reloadAsRoot(pkg: string): Promise<boolean> {
42
        try {
43
            await execa('sudo', ['brew', 'services', 'reload', pkg], {shell: true})
44
            return true
45
        } catch (e) {
46
            return false
47
        }
48
    }
49
50
    async restartAsRoot(pkg: string): Promise<boolean> {
51
        try {
52
            await execa('sudo', ['brew', 'services', 'restart', pkg], {shell: true})
53
            return true
54
        } catch (e) {
55
            return false
56
        }
57
    }
58
59
    async startAsRoot(pkg: string): Promise<boolean> {
60
        try {
61
            await execa('sudo', ['brew', 'services', 'start', pkg], {shell: true})
62
            return true
63
        } catch (e) {
64
            return false
65
        }
66
    }
67
68
    async stopAsRoot(pkg: string): Promise<boolean> {
69
        try {
70
            await execa('sudo', ['brew', 'services', 'stop', pkg], {shell: true})
71
            return true
72
        } catch (e) {
73
            return false
74
        }
75
    }
76
77
    async link(pkg: string): Promise<boolean> {
78
        try {
79
            await execa('brew', ['link', '--overwrite', '--force', pkg], {shell: true})
80
            return true
81
        } catch (e) {
82
            return false
83
        }
84
    }
85
86
    async unlink(pkg: string): Promise<boolean> {
87
        try {
88
            await execa('brew', ['unlink', pkg], {shell: true})
89
            return true
90
        } catch (e) {
91
            return false
92
        }
93
    }
94
}
95
96
export default BrewServices